package org.jshand.cloud.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 作者: 张金山
 * 创建时间：2025/2/11 19:33   星期二
 * 描述： 服务提供者控制器
 * 项目: spring-cloud-alibaba - org.jshand.cloud.controller
 * 作者的博客:  https://blog.fulfill.com.cn
 */

@Slf4j
@RestController
@RequestMapping("/consumer")
public class ConsumerUserController {


    /**
     * 获取当前应用名称
     */
    @Value("${spring.application.name}")
    private String appName;



    @Autowired
    private RestTemplate restTemplate;



    @RequestMapping("/user/index")
    String index(){
        String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        return appName+"@"+time;
    }


    @RequestMapping("/user/order/{userId}")
    String getProvider(@PathVariable("userId") int userId){

        log.info("服务消费者，获取订单信息:用户id{}",userId);


        String url = "http://127.0.0.1:7001/provider/order/"+userId;
        String orderInfo = restTemplate.getForObject(url, String.class);
        return "用户微服务："+orderInfo;
    }


}
